/*
 * Copyright (c) 2021 chwxu@outlook.com
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
<template>
  <a-card>
    <a-table :columns="columns" :data-source="data" :scroll="{ x: 1900, y: 500 }">
      <template #time_dispatched="{ text }">
        <a :href="'/cicd/' + text">{{ text }}</a>
      </template>
    </a-table>
  </a-card>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { Card, Table } from 'ant-design-vue';
import 'highlight.js/styles/github.css';
import 'github-markdown-css';
import { elapsedTime } from './dateUtils';

const columns = [
  { title: '触发人员', dataIndex: '触发人员', key: 'name', width: 130, fixed: 'left' },
  {
    title: '调度时间',
    dataIndex: '调度时间',
    key: 'time_dispatched',
    width: 120,
    fixed: 'left',
    slots: { customRender: 'time_dispatched' },
  },
  { title: '耗时', dataIndex: '耗时', key: 'time_elapsed', width: 80, fixed: 'left' },
  {
    title: 'hispark_pegasus',
    children: [
      {
        title: 'debug',
        dataIndex: 'hispark_pegasus/debug',
        key: 'hispark_pegasus/debug',
        width: 80,
      },
      {
        title: 'test',
        dataIndex: 'hispark_pegasus/test',
        key: 'hispark_pegasus/test',
        width: 80,
      },
    ],
  },
  {
    title: 'hispark_aries',
    children: [
      {
        title: 'debug',
        dataIndex: 'hispark_aries/debug',
        key: 'hispark_aries/debug',
        width: 80,
      },
      {
        title: 'test',
        dataIndex: 'hispark_aries/test',
        key: 'hispark_aries/test',
        width: 80,
      },
    ],
  },
  {
    title: 'hispark_taurus_LiteOS',
    children: [
      {
        title: 'debug',
        dataIndex: 'hispark_taurus_LiteOS/debug',
        key: 'hispark_taurus_LiteOS/debug',
        width: 100,
      },
      {
        title: 'test',
        dataIndex: 'hispark_taurus_LiteOS/test',
        key: 'hispark_taurus_LiteOS/test',
        width: 100,
      },
    ],
  },
  {
    title: 'hispark_taurus_Linux',
    children: [
      {
        title: 'debug',
        dataIndex: 'hispark_taurus_Linux/debug',
        key: 'hispark_taurus_Linux/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'hispark_taurus_L2',
    children: [
      {
        title: 'debug',
        dataIndex: 'hispark_taurus_L2/debug',
        key: 'hispark_taurus_L2/debug',
        width: 80,
      },
      {
        title: 'test',
        dataIndex: 'hispark_taurus_L2/test',
        key: 'hispark_taurus_L2/test',
        width: 80,
      },
    ],
  },
  {
    title: 'L2_ohos-arm64',
    children: [
      {
        title: 'debug',
        dataIndex: 'L2_ohos-arm64/debug',
        key: 'L2_ohos-arm64/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'ohos-sdk',
    children: [
      {
        title: 'debug',
        dataIndex: 'ohos-sdk/debug',
        key: 'ohos-sdk/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'API_Guard',
    children: [
      {
        title: 'debug',
        dataIndex: 'API_Guard/debug',
        key: 'API_Guard/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'L0_Emulator',
    children: [
      {
        title: 'debug',
        dataIndex: 'L0_Emulator/debug',
        key: 'L0_Emulator/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'L0_Riscv_Emulator',
    children: [
      {
        title: 'debug',
        dataIndex: 'L0_Riscv_Emulator/debug',
        key: 'L0_Riscv_Emulator/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'L1_Emulator',
    children: [
      {
        title: 'debug',
        dataIndex: 'L1_Emulator/debug',
        key: 'L1_Emulator/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'hispark_taurus_ark',
    children: [
      {
        title: 'debug',
        dataIndex: 'hispark_taurus_ark/debug',
        key: 'hispark_taurus_ark/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'hispark_taurus_ark_runtime',
    children: [
      {
        title: 'debug',
        dataIndex: 'hispark_taurus_ark_runtime/debug',
        key: 'hispark_taurus_ark_runtime/debug',
        width: 80,
      },
    ],
  },
  {
    title: 'hispark_taurus_ark_unittest',
    children: [
      {
        title: 'debug',
        dataIndex: 'hispark_taurus_ark_unittest/debug',
        key: 'hispark_taurus_ark_unittest/debug',
        width: 80,
      },
    ],
  },
  { title: '静态检查', dataIndex: '静态检查', key: 'static_check' },
];

interface DataItem {
  key: string;
  触发人员: string;
  调度时间: string;
  耗时: string;
  'hispark_pegasus/debug': string;
  'hispark_pegasus/test': string;
  'hispark_aries/debug': string;
  'hispark_aries/test': string;
  'hispark_taurus_LiteOS/debug': string;
  'hispark_taurus_LiteOS/test': string;
  'hispark_taurus_Linux/debug': string;
  'hispark_taurus_L2/debug': string;
  'hispark_taurus_L2/test': string;
  'L2_ohos-arm64/debug': string;
  'ohos-sdk/debug': string;
  'API_Guard/debug': string;
  'L0_Emulator/debug': string;
  'L0_Riscv_Emulator/debug': string;
  'L1_Emulator/debug': string;
  'hispark_taurus_ark/debug': string;
  'hispark_taurus_ark_runtime/debug': string;
  'hispark_taurus_ark_unittest/debug': string;
  静态检查: string;
}

const data: DataItem[] = [];
for (let i = 0; i < 1; i++) {
  data.push({
    key: 'i',
    触发人员: `Edrward ${i}`,
    调度时间: new Date(Date.now()).toLocaleString(),
    耗时: elapsedTime(Math.random() * 1e6),
    'hispark_pegasus/debug': '成功',
    'hispark_pegasus/test': '成功',
    'hispark_aries/debug': '成功',
    'hispark_aries/test': '成功',
    'hispark_taurus_LiteOS/debug': '成功',
    'hispark_taurus_LiteOS/test': '成功',
    'hispark_taurus_Linux/debug': '成功',
    'hispark_taurus_L2/debug': '成功',
    'hispark_taurus_L2/test': '成功',
    'L2_ohos-arm64/debug': '成功',
    'ohos-sdk/debug': '成功',
    'API_Guard/debug': '成功',
    'L0_Emulator/debug': '成功',
    'L0_Riscv_Emulator/debug': '成功',
    'L1_Emulator/debug': '成功',
    'hispark_taurus_ark/debug': '成功',
    'hispark_taurus_ark_runtime/debug': '成功',
    'hispark_taurus_ark_unittest/debug': '成功',
    静态检查: '成功',
  });
}

export default defineComponent({
  components: {
    ACard: Card,
    ATable: Table,
  },
  data() {
    return {
      data,
      columns,
    };
  },
});
</script>
<style>
/* .markdown-body {
  box-sizing: border-box;
  min-width: 200px;
  max-width: 980px;
  margin: 0 auto;
  padding: 45px;
} */
</style>
